<?php
	header("Conten-type:text/html;charset=utf-8");
	
	init();
	
	//初始方法
	function init(){
		if($_GET['d'] != null){
			get();
		}
		else if($_GET['ds'] != null){
			gets();
		}
		else{
			header("Location: http://opendata.yzhaj.club/date/index.html");
		}
	}
	
	//获取数据单个
	function get(){
		$ymd = explode("-", $_GET['d']);
		
		if(!file_exists($ymd[0].'.json')){
			exit('文件数据不存在，请联系管理员 QQ:1076212909');
		}
		
		$data  = file_get_contents($ymd[0].'.json');
		$data = json_decode($data,true);
		
		$result = array();
		$result['data'] = $data[ $_GET['d'] ];
		
		if(!$result['data']){
			$result['message'] = "数据不存在";
			$result['status'] = -100;
			echo json_encode($result);
			exit();
		}
		else{
			$result['message'] = "成功";
			$result['status'] = -100;
			echo json_encode($result);
			exit();
		}
		
	}
	
	
	//获取数据多个
	function gets(){
		
		$ymd = explode("-", $_GET['ds']);
		
		if(!file_exists($ymd[0].'.json')){
			exit('文件数据不存在，请联系管理员 QQ:1076212909');
		}
		
		$data  = file_get_contents($ymd[0].'.json');
		$data = json_decode($data,true);
		
		$result = array();
		$result['data'] = array();
		
		$length = strlen($_GET['ds']);
		
		foreach ($data as $key => $value){
			if(substr($key,0,$length) == $_GET['ds']){
				$result['data'][] = $value;
			}
		}
		
		if(count($result['data']) == 0){
			$result['message'] = "数据不存在";
			$result['status'] = -100;
			echo json_encode($result);
			exit();
		}
		else{
			$result['message'] = "成功";
			$result['status'] = -100;
			echo json_encode($result);
			exit();
		}
	}
	
?>